from typing import List


class Solution:
    def getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]:
        n=len(nums)
        # 前缀和数组
        pre=[0]*(n+1)
        for i in range(n):
            pre[i+1]=pre[i]+nums[i]
        ans=[]
        for i in range(n):
            # 分为左右 小于 nums[i]的  and 大于 nums[i]的
            left = nums[i]*i-pre[i]

            right = pre[n]-pre[i+1]-nums[i]*(n-i-1)
            ans.append(left+right)
        return ans